package code.codeworld;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication
public class CodeworldApplication {

    public static void main(String[] args) throws UnknownHostException {
        //SpringApplication.run(CodeworldManageApplication.class, args);

        ConfigurableApplicationContext application = SpringApplication.run(CodeworldApplication.class, args);

        System.out.println(
                """      
                         ______   ______   ______   ______   __ __ __   ______   ______    __       ______            __ __ __   ______    _______       ______   __  __   ______   ______   ______   ______   ______   __      \s
                        /_____/\\ /_____/\\ /_____/\\ /_____/\\ /_//_//_/\\ /_____/\\ /_____/\\  /_/\\     /_____/\\          /_//_//_/\\ /_____/\\ /_______/\\     /_____/\\ /_/\\/_/\\ /_____/\\ /_____/\\ /_____/\\ /_____/\\ /_____/\\ /__/\\    \s
                        \\:::__\\/ \\:::_ \\ \\\\:::_ \\ \\\\::::_\\/_\\:\\\\:\\\\:\\ \\\\:::_ \\ \\\\:::_ \\ \\ \\:\\ \\    \\:::_ \\ \\         \\:\\\\:\\\\:\\ \\\\::::_\\/_\\::: _  \\ \\    \\::::_\\/_\\:\\ \\:\\ \\\\:::__\\/ \\:::__\\/ \\::::_\\/_\\::::_\\/_\\::::_\\/_\\.:\\ \\   \s
                         \\:\\ \\  __\\:\\ \\ \\ \\\\:\\ \\ \\ \\\\:\\/___/\\\\:\\\\:\\\\:\\ \\\\:\\ \\ \\ \\\\:(_) ) )_\\:\\ \\    \\:\\ \\ \\ \\         \\:\\\\:\\\\:\\ \\\\:\\/___/\\\\::(_)  \\/_    \\:\\/___/\\\\:\\ \\:\\ \\\\:\\ \\  __\\:\\ \\  __\\:\\/___/\\\\:\\/___/\\\\:\\/___/\\\\::\\ \\  \s
                          \\:\\ \\/_/\\\\:\\ \\ \\ \\\\:\\ \\ \\ \\\\::___\\/_\\:\\\\:\\\\:\\ \\\\:\\ \\ \\ \\\\: __ `\\ \\\\:\\ \\____\\:\\ \\ \\ \\  _______\\:\\\\:\\\\:\\ \\\\::___\\/_\\::  _  \\ \\    \\_::._\\:\\\\:\\ \\:\\ \\\\:\\ \\/_/\\\\:\\ \\/_/\\\\::___\\/_\\_::._\\:\\\\_::._\\:\\\\__\\/_ \s
                           \\:\\_\\ \\ \\\\:\\_\\ \\ \\\\:\\/.:| |\\:\\____/\\\\:\\\\:\\\\:\\ \\\\:\\_\\ \\ \\\\ \\ `\\ \\ \\\\:\\/___/\\\\:\\/.:| |/______/\\\\:\\\\:\\\\:\\ \\\\:\\____/\\\\::(_)  \\ \\     /____\\:\\\\:\\_\\:\\ \\\\:\\_\\ \\ \\\\:\\_\\ \\ \\\\:\\____/\\ /____\\:\\ /____\\:\\ /__/\\\s
                            \\_____\\/ \\_____\\/ \\____/_/ \\_____\\/ \\_______\\/ \\_____\\/ \\_\\/ \\_\\/ \\_____\\/ \\____/_/\\__::::\\/ \\_______\\/ \\_____\\/ \\_______\\/     \\_____\\/ \\_____\\/ \\_____\\/ \\_____\\/ \\_____\\/ \\_____\\/ \\_____\\/ \\__\\/\s
                        """);

        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                "CodeworldApplication  is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + path + "\n\t" +
                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
                "----------------------------------------------------------");
        String jvmName = ManagementFactory.getRuntimeMXBean().getName();
        log.info("当前项目进程号：" + jvmName.split("@")[0]);

    }


}
